<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>欢迎来到guo的博客!</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta property="og:type" content="website">
<meta property="og:title" content="欢迎来到guo的博客!">
<meta property="og:url" content="http://shangguan-lingfeng.gitee.io/blog1/index.html">
<meta property="og:site_name" content="欢迎来到guo的博客!">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Jerry">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog1/atom.xml" title="欢迎来到guo的博客!" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog1/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog1/css/style.css">

  
    
<link rel="stylesheet" href="/blog1/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog1/" id="logo">欢迎来到guo的博客!</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog1/">Home</a>
        
          <a class="main-nav-link" href="/blog1/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog1/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Suche"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://shangguan-lingfeng.gitee.io/blog1"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main">
  
    <article id="post-docker+CentOS+mysql实现主从同步" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" class="article-date">
  <time class="dt-published" datetime="2021-05-13T16:00:00.000Z" itemprop="datePublished">2021-05-14</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">docker+CentOS+mysql实现主从同步</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="docker在云主机实现主从同步"><a href="#docker在云主机实现主从同步" class="headerlink" title="docker在云主机实现主从同步"></a>docker在云主机实现主从同步</h3><p>我们已经实现了云主机的主从同步，那么我们可以尝试一下在docker创建容器来实现mysql的主从同步</p>
<h5 id="1-生成mysql容器并启动"><a href="#1-生成mysql容器并启动" class="headerlink" title="1.生成mysql容器并启动"></a>1.生成mysql容器并启动</h5><p>如果你没有mysql需要你去dockerhub上拉取下来,这里我拉取的版本是mysql5.7</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull mysql:5.7</span><br></pre></td></tr></table></figure>
<p>使用docker来查看我们的镜像(没有安装docker可以去我的docker中查看，有具体教程)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@iz2zedf9acxaowfuu9lzunz ~]# docker images</span><br><span class="line">REPOSITORY    TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">redis         latest    739b59b96069   3 weeks ago    105MB</span><br><span class="line">mysql         5.7       87eca374c0ed   3 weeks ago    447MB</span><br><span class="line">hello-world   latest    d1165f221234   2 months ago   13.3kB</span><br><span class="line">centos        7         8652b9f0cb4c   6 months ago   204MB</span><br></pre></td></tr></table></figure>
<p>接下来需要启动镜像，生成容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// docker开启mysql容器</span><br><span class="line">docker run --name mysql1 -p 3305:3306 -v /home/mysql/conf1:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=1234 -d mysql:5.7</span><br><span class="line"></span><br><span class="line">// docker进入启动容器</span><br><span class="line">docker exec -it 82b436bb26de /bin/bash</span><br></pre></td></tr></table></figure>
<h5 id="2-配置my-cnf文件"><a href="#2-配置my-cnf文件" class="headerlink" title="2.配置my.cnf文件"></a>2.配置my.cnf文件</h5><p>这时可以另行开启一个连接，由于我使用了-v本地云主机的目录对于镜像目录的映射，可以直接在云主机目录上配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /home/mysql</span><br><span class="line">mkdir conf1</span><br><span class="line">cd conf1/</span><br></pre></td></tr></table></figure>
<p>配置主库my.cnf文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line">log-bin=master-bin  # 指定bin-log二进制日志</span><br><span class="line">server-id=1  # 指定服务ID, 在从服务器也有, 主库和从库ID不可设置相同</span><br><span class="line">binlog-format=ROW  # bin-log格式</span><br></pre></td></tr></table></figure>
<p>进入容器，重启服务</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">root@82b436bb26de:/etc/mysql/conf.d# service mysql restart</span><br><span class="line">[info] Stopping MySQL Community Server 5.7.34.</span><br></pre></td></tr></table></figure>
<p>这时容器会停止，我们重新开启容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start 82b436bb26de</span><br></pre></td></tr></table></figure>
<h5 id="3-创建从库连接"><a href="#3-创建从库连接" class="headerlink" title="3.创建从库连接"></a>3.创建从库连接</h5><p>进入mysql创建从库的连接</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">CREATE USER &#x27;master&#x27;@&#x27;8.131.52.82&#x27; IDENTIFIED BY &#x27;1234&#x27;;</span><br><span class="line"></span><br><span class="line">GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO &#x27;master&#x27;@&#x27;%&#x27;;</span><br></pre></td></tr></table></figure>
<h5 id="4-配置从库"><a href="#4-配置从库" class="headerlink" title="4.配置从库"></a>4.配置从库</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line"><span class="meta">#</span><span class="bash"><span class="comment"># 设置server_id,注意要唯一</span></span></span><br><span class="line">server-id=2</span><br><span class="line"><span class="meta">#</span><span class="bash"><span class="comment"># 开启二进制日志功能，以备Slave作为其它Slave的Master时使用</span></span></span><br><span class="line">log-bin=mysql-slave-bin   </span><br><span class="line"><span class="meta">#</span><span class="bash"><span class="comment"># relay_log配置中继日志</span></span></span><br><span class="line">relay_log=edu-mysql-relay-bin</span><br></pre></td></tr></table></figure>
<p>现在主服务器中进入主库查看master状态</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">show master status;</span><br></pre></td></tr></table></figure>
<p><img src="http://songwenjie.vip/blog/180726/Kjja2jAIm4.png?imageslim" alt="master状态"></p>
<p>从服务器(云主机)启动mysql</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p</span><br><span class="line">密码：</span><br></pre></td></tr></table></figure>
<p>进入mysql后配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">change master to master_host=&#x27;8.131.52.82&#x27;, </span><br><span class="line">master_user=&#x27;master&#x27;, </span><br><span class="line">master_password=&#x27;1234&#x27;, </span><br><span class="line">master_port=3305, </span><br><span class="line">master_log_file=&#x27;mysql-bin.000001&#x27;, # 主库master里的file</span><br><span class="line">master_log_pos= 2830,   # 主库master里的pos</span><br><span class="line">master_connect_retry=30;    # 超时时长</span><br></pre></td></tr></table></figure>
<p>然后开启从库连接</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">start slave;</span><br></pre></td></tr></table></figure>
<p>在Slave 中的mysql终端执行show slave status \G;用于查看主从同步状态。<br><img src="http://songwenjie.vip/blog/180726/FG2ja42l86.png?imageslim" alt="主从同步状态"></p>
<p>SlaveIORunning 和 SlaveSQLRunning 都是Yes，说明主从复制已经开启。此时可以测试数据同步是否成功。</p>
<h5 id="5-进行测试"><a href="#5-进行测试" class="headerlink" title="5.进行测试"></a>5.进行测试</h5><p>主库创建一个数据库<br><img src="http://songwenjie.vip/blog/180726/Kg1EB8f1HL.png?imageslim" alt="主库"></p>
<p>查看从库是否有主库创建的数据库<br><img src="http://songwenjie.vip/blog/180726/4Ibh3CF9D3.png?imageslim" alt="从库"></p>
<p>至此主从同步实现完成</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" data-id="ckoobpobx0000z8uh3cu73zpn" data-title="docker+CentOS+mysql实现主从同步" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/docker/" rel="tag">docker</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-mysql实现读写分离(在主从同步基础上)" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/" class="article-date">
  <time class="dt-published" datetime="2021-05-12T16:00:00.000Z" itemprop="datePublished">2021-05-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/">mysql实现读写分离</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="读写分离"><a href="#读写分离" class="headerlink" title="读写分离"></a>读写分离</h3><p>在Web应用中，读写比例一般在10:1，配置读写分离，写的操作放在主库，从库负责读取数据。<br>可以根据读写的需求调整成一主多从，多主一从，多主多从。</p>
<h5 id="1-Flask实现读写分离"><a href="#1-Flask实现读写分离" class="headerlink" title="1.Flask实现读写分离"></a>1.Flask实现读写分离</h5><p>在我们创建的model目录的__init__中配置读写分离，创建db</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Flask中实现读写分离</span></span><br><span class="line"><span class="comment"># flask_sqlalchemy是对sqlalchemy进行的封装，更适合Flask数据库的使用</span></span><br><span class="line"><span class="keyword">from</span> flask_sqlalchemy <span class="keyword">import</span> SQLAlchemy, SignallingSession, get_state</span><br><span class="line"><span class="keyword">from</span> sqlalchemy <span class="keyword">import</span> orm</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RoutingSession</span>(<span class="params">SignallingSession</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_bind</span>(<span class="params">self, mapper=<span class="literal">None</span>, clause=<span class="literal">None</span></span>):</span></span><br><span class="line">        state = get_state(self.app)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># _flushing用来判断读写操作</span></span><br><span class="line">        <span class="keyword">if</span> self._flushing:  <span class="comment"># 写操作,使用主数据库，从配置好的master主库写入数据</span></span><br><span class="line">            print(<span class="string">&quot;写入数据&quot;</span>)</span><br><span class="line">            <span class="keyword">return</span> state.db.get_engine(self.app, bind=<span class="string">&#x27;master&#x27;</span>)</span><br><span class="line">        <span class="keyword">else</span>:  <span class="comment"># 读操作,使用从数据库，从配置好的slave</span></span><br><span class="line">            print(<span class="string">&#x27;读取数据&#x27;</span>)</span><br><span class="line">            <span class="keyword">return</span> state.db.get_engine(self.app, bind=<span class="string">&#x27;slave&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RoutingSQLAlchemy</span>(<span class="params">SQLAlchemy</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">create_session</span>(<span class="params">self, options</span>):</span></span><br><span class="line">        <span class="keyword">return</span> orm.sessionmaker(class_=RoutingSession, db=self, **options)</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 配置中写如下配置</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置数据库绑定地址，设置此地址后就无需之前的数据库链接地址SQLALCHEMY_DATABASE_URI</span></span><br><span class="line">SQLALCHEMY_BINDS = &#123;</span><br><span class="line">    <span class="string">&#x27;master&#x27;</span>: <span class="string">&quot;mysql+pymysql://主库用户:主库密码@8.131.52.82:3306/主库&quot;</span>,</span><br><span class="line">    <span class="string">&#x27;slave&#x27;</span>: <span class="string">&quot;mysql+pymysql://主库创建从库用户(username):password@从服务器IP:3306/从库&quot;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置是否追踪数据变化。一般不会开启，会影响性能</span></span><br><span class="line">SQLALCHEMY_TRACK_MODIFICATIONS = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置是否打印底层执行的SQL语句</span></span><br><span class="line">SQLALCHEMY_ECHO = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 实例化db的时候:</span></span><br><span class="line">db = RoutingSQLAlchemy(app)</span><br></pre></td></tr></table></figure>
<h5 id="2-Django实现读写分离"><a href="#2-Django实现读写分离" class="headerlink" title="2.Django实现读写分离"></a>2.Django实现读写分离</h5><p>settings.py中配置</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">DATABASES = &#123;</span><br><span class="line"> <span class="string">&#x27;default&#x27;</span>: &#123;</span><br><span class="line"> <span class="string">&#x27;ENGINE&#x27;</span>: <span class="string">&#x27;django.db.backends.mysql&#x27;</span>,</span><br><span class="line"> <span class="string">&#x27;HOST&#x27;</span>: <span class="string">&#x27;127.0.0.1&#x27;</span>, <span class="comment"># 主服务器的运行ip</span></span><br><span class="line"> <span class="string">&#x27;PORT&#x27;</span>: <span class="number">3306</span>, <span class="comment"># 主服务器的运行port</span></span><br><span class="line"> <span class="string">&#x27;USER&#x27;</span>: <span class="string">&#x27;django&#x27;</span>, <span class="comment"># 主服务器的用户名</span></span><br><span class="line"> <span class="string">&#x27;PASSWORD&#x27;</span>: <span class="string">&#x27;django&#x27;</span>, <span class="comment"># 主服务器的密码</span></span><br><span class="line"> <span class="string">&#x27;NAME&#x27;</span>: <span class="string">&#x27;djangobase&#x27;</span> <span class="comment"># 数据库名</span></span><br><span class="line"> &#125;,</span><br><span class="line"> <span class="string">&#x27;slave&#x27;</span>: &#123;</span><br><span class="line"> <span class="string">&#x27;ENGINE&#x27;</span>: <span class="string">&#x27;django.db.backends.mysql&#x27;</span>, </span><br><span class="line"> <span class="string">&#x27;HOST&#x27;</span>: <span class="string">&#x27;127.0.0.1&#x27;</span>, <span class="comment"># 从服务器的运行ip</span></span><br><span class="line"> <span class="string">&#x27;PORT&#x27;</span>: <span class="number">3305</span>, <span class="comment"># 从服务器的运行port</span></span><br><span class="line"> <span class="string">&#x27;USER&#x27;</span>: <span class="string">&#x27;django_slave&#x27;</span>, <span class="comment"># 主服务器的用户名</span></span><br><span class="line"> <span class="string">&#x27;PASSWORD&#x27;</span>: <span class="string">&#x27;1234&#x27;</span>, <span class="comment"># 主服务器的密码</span></span><br><span class="line"> <span class="string">&#x27;NAME&#x27;</span>: <span class="string">&#x27;mydatabase&#x27;</span> <span class="comment"># 从数据库名</span></span><br><span class="line"> &#125;</span><br><span class="line">&#125;　　</span><br></pre></td></tr></table></figure>
<p>对数据库进行迁移</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">python manage.py makemigrations <span class="comment"># 在migrations文件夹下生成记录</span></span><br><span class="line">python manage.py migrate --database default <span class="comment"># 默认可以不写参数</span></span><br><span class="line">python manage.py migrate --database db2 <span class="comment"># 在从库再迁移一次，就可以在上面建立相同的表</span></span><br></pre></td></tr></table></figure>
<p>在项目的<strong>init</strong>.py文件下配置,将数据连接方式改为pymysql</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pymysql</span><br><span class="line">pymysql.install_as_MySQLdb()</span><br></pre></td></tr></table></figure>
<p>自动读写分离</p>
<p>通过配置数据库路由，来自动实现读写分离，这样就不需要每次读写都手动指定数据库。<br>在项目的app中创建db_router.py文件,并在该文件中定义一个数据库路由类,用来进行读写分离，这个类最多提供四个方法，分别是：db_for_read、<br>db_for_write、allow_relation、allow_migrate，以下只写了三个。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MasterSlaveDBRouter</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line"> <span class="string">&quot;&quot;&quot;数据库主从读写分离路由&quot;&quot;&quot;</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">db_for_read</span>(<span class="params">self, model, **hints</span>):</span></span><br><span class="line"> <span class="string">&quot;&quot;&quot;读数据库&quot;&quot;&quot;</span></span><br><span class="line"> <span class="keyword">return</span> <span class="string">&quot;slave&quot;</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">db_for_write</span>(<span class="params">self, model, **hints</span>):</span></span><br><span class="line"> <span class="string">&quot;&quot;&quot;写数据库&quot;&quot;&quot;</span></span><br><span class="line"> <span class="keyword">return</span> <span class="string">&quot;default&quot;</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">allow_relation</span>(<span class="params">self, obj1, obj2, **hints</span>):</span></span><br><span class="line"> <span class="string">&quot;&quot;&quot;是否运行关联操作&quot;&quot;&quot;</span></span><br><span class="line"> <span class="keyword">return</span> <span class="literal">True</span></span><br></pre></td></tr></table></figure>
<p>settings.py文件中配置</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DATABASE_ROUTERS = [<span class="string">&quot;app001.db_router.MasterSlaveDBRouter&quot;</span>]</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/" data-id="ckomwm8uy0003cguhfeww8jhq" data-title="mysql实现读写分离" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/mysql/" rel="tag">mysql</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-在项目中自动生成接口文档" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/" class="article-date">
  <time class="dt-published" datetime="2021-05-12T03:23:23.071Z" itemprop="datePublished">2021-05-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/">在项目中自动生成接口文档</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <hr>
<h3 id="实现django项目自动生成接口文档"><a href="#实现django项目自动生成接口文档" class="headerlink" title="实现django项目自动生成接口文档"></a>实现django项目自动生成接口文档</h3><h5 id="1-首先安装我们需要的coreapi"><a href="#1-首先安装我们需要的coreapi" class="headerlink" title="1.首先安装我们需要的coreapi"></a>1.首先安装我们需要的coreapi</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install coreapi</span><br></pre></td></tr></table></figure>
<h5 id="2-在settings-py文件中进行配置"><a href="#2-在settings-py文件中进行配置" class="headerlink" title="2.在settings.py文件中进行配置"></a>2.在settings.py文件中进行配置</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 配置文档</span></span><br><span class="line">REST_FRAMEWORK = &#123;</span><br><span class="line">    <span class="string">&#x27;DEFAULT_SCHEMA_CLASS&#x27;</span>: <span class="string">&#x27;rest_framework.schemas.coreapi.AutoSchema&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="3-在主路由urls-py文件中导入模块，配置文档路由"><a href="#3-在主路由urls-py文件中导入模块，配置文档路由" class="headerlink" title="3.在主路由urls.py文件中导入模块，配置文档路由"></a>3.在主路由urls.py文件中导入模块，配置文档路由</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.contrib <span class="keyword">import</span> admin</span><br><span class="line"><span class="keyword">from</span> django.urls <span class="keyword">import</span> path,include</span><br><span class="line"></span><br><span class="line"><span class="comment"># 导入此包</span></span><br><span class="line"><span class="keyword">from</span> rest_framework.documentation <span class="keyword">import</span> include_docs_urls</span><br><span class="line"></span><br><span class="line">urlpatterns = [</span><br><span class="line">    path(<span class="string">&#x27;admin/&#x27;</span>, admin.site.urls),</span><br><span class="line">    path(<span class="string">&#x27;&#x27;</span>,include(<span class="string">&#x27;testapp.urls&#x27;</span>)),</span><br><span class="line">    path(<span class="string">&#x27;&#x27;</span>,include(<span class="string">&#x27;user.urls&#x27;</span>)),</span><br><span class="line">    path(<span class="string">&#x27;&#x27;</span>,include(<span class="string">&#x27;worker.urls&#x27;</span>)),</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 这是我配置的文档路由</span></span><br><span class="line">    path(<span class="string">&quot;docs/&quot;</span>,include_docs_urls(title=<span class="string">&quot;接口文档&quot;</span>))</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/" data-id="ckokwns680000jsuh31qo5jx7" data-title="在项目中自动生成接口文档" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/django/" rel="tag">django</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-mysql实现主从同步" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" class="article-date">
  <time class="dt-published" datetime="2021-05-11T16:00:00.000Z" itemprop="datePublished">2021-05-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">mysql实现主从同步</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="一、关于mysql主从同步"><a href="#一、关于mysql主从同步" class="headerlink" title="一、关于mysql主从同步"></a>一、关于mysql主从同步</h3><p>在复杂的业务中，我们会对数据进行加表级锁锁定，而其它的事务无法对其进行读的操作。<br>那么我们就会需要mysql数据库读写都能正常进行，也就是mysql的读写分离。</p>
<p>而实现读写分离我们需要多个数据库的数据保持一致，才能进行设置读写数据库的配置。</p>
<p>指一台服务器充当主数据库服务器，另一台或多台服务器充当从数据库服务器，主服务器中的数据自动复制到从服务器之中。对于多级复制，数据库服务器即可充当主机，也可充当从机。<br>MySQL主从复制的基础是主服务器对数据库修改记录二进制日志，从服务器通过主服务器的二进制日志自动执行更新。<br>主库和从库实现同步。<br><img src="https://upload-images.jianshu.io/upload_images/5009863-865d52a5f616a52d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/506/format/webp" alt="mysql主从同步"></p>
<h3 id="二、实现主从同步"><a href="#二、实现主从同步" class="headerlink" title="二、实现主从同步"></a>二、实现主从同步</h3><h5 id="1-我们首先进入mysql数据库，开启两个服务器分别创建相同名称的数据库"><a href="#1-我们首先进入mysql数据库，开启两个服务器分别创建相同名称的数据库" class="headerlink" title="1.我们首先进入mysql数据库，开启两个服务器分别创建相同名称的数据库"></a>1.我们首先进入mysql数据库，开启两个服务器分别创建相同名称的数据库</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 在服务器1中</span><br><span class="line">create database mydatabase charset utf8;</span><br><span class="line"></span><br><span class="line">// 在服务器2中</span><br><span class="line">create database mydatabase charset utf8;</span><br></pre></td></tr></table></figure>

<h5 id="2-然后需要对主库进行配置"><a href="#2-然后需要对主库进行配置" class="headerlink" title="2.然后需要对主库进行配置"></a>2.然后需要对主库进行配置</h5><p>进入 /etc/my.cnf文件中配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">log-bin=master-bin  # 指定bin-log二进制日志</span><br><span class="line">server-id=1  # 指定服务ID, 在从服务器也有, 主库和从库ID不可设置相同</span><br><span class="line">binlog-format=ROW  # bin-log格式</span><br><span class="line">binlog-do-db=mydatabase  # 指定主库</span><br></pre></td></tr></table></figure>
<p>然后重启数据库</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart mysqld</span><br></pre></td></tr></table></figure>
<h5 id="3-主库创建账号并授权"><a href="#3-主库创建账号并授权" class="headerlink" title="3.主库创建账号并授权"></a>3.主库创建账号并授权</h5><p>先进入mysql中</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p</span><br><span class="line">密码：</span><br></pre></td></tr></table></figure>
<p>进入mysql中然后进入mysql库中</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">use mysql;</span><br><span class="line">// 创建用户(如果拥有该用户则不用创建)</span><br><span class="line">create user username identified by &#x27;password&#x27;;   # 我们一般不会在slave连接master中直接使用root用户，而是给他分配一个其他的账户。</span><br><span class="line"> </span><br><span class="line">// 赋予该用户复制的权利</span><br><span class="line">grant replication slave on *.* to &#x27;username&#x27;@&#x27;主机ID&#x27; identified by &#x27;password&#x27;;</span><br><span class="line"> </span><br><span class="line">// 需要flush数据库,使得配置生效</span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>
<h5 id="5-进入从库进行配置"><a href="#5-进入从库进行配置" class="headerlink" title="5.进入从库进行配置"></a>5.进入从库进行配置</h5><p>进入 /etc/my.cnf文件中配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">log-bin=master-bin  # 二进制日志的名字, 要与主库相同</span><br><span class="line">binlog-format=ROW  # 日志的格式, 也要与主库相同</span><br><span class="line">server-id=2  # 服务ID，ID与主库不能相同</span><br></pre></td></tr></table></figure>
<p>同样，从库也重启数据库</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart mysqld</span><br></pre></td></tr></table></figure>
<p>进入从库mysql中</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p</span><br><span class="line">密码：</span><br></pre></td></tr></table></figure>
<p>查看<strong>主库</strong>的状态(进入mysql查看)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">show master status;</span><br></pre></td></tr></table></figure>
<p>我们会查到这张表，这张表对于我们非常有用，可以先截图记录下来</p>
<h1 id="7-在从库中设置主库的连接"><a href="#7-在从库中设置主库的连接" class="headerlink" title="7.在从库中设置主库的连接"></a>7.在从库中设置主库的连接</h1><p>同样在<strong>从库</strong>mysql中从库连接主库的操作，注意bin.000005为查看主库状态所得到的编号，每个人不一定一样</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">change master to master_host=&#x27;主库主机ID&#x27;, </span><br><span class="line">master_user=&#x27;username&#x27;, </span><br><span class="line">master_password=&#x27;password&#x27;, </span><br><span class="line">master_log_file=&#x27;master-bin.000005&#x27;, </span><br><span class="line">master_log_pos=245;</span><br></pre></td></tr></table></figure>
<p>如果报错 ERROR1198，先停止<strong>从库</strong>，再重新执行上一步命令即可</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">stop slave;</span><br></pre></td></tr></table></figure>
<p>重新开启从库</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">start slave;</span><br></pre></td></tr></table></figure>
<p>从服务器查看从库的状态</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">show slave status \G</span><br></pre></td></tr></table></figure>
<p>查看一下两条线程是否为Yes,如果IO为No，先去主服务器主库编号是否发生改变，改变后则需要重新进行从库配置<br>Slave_IO_Running: Yes<br>Slave_SQL_Running: Yes</p>
<h3 id="三、实现主从同步的作用"><a href="#三、实现主从同步的作用" class="headerlink" title="三、实现主从同步的作用"></a>三、实现主从同步的作用</h3><p>1.用于数据备份, 保证数据的安全<br>主从复制可以实现从服务器作为主服务器的实时数据备份. 主服务器架构的设置, 可以大大加强mysql数据库的健壮性。<br>2.实现读写分离, 提高吞吐量<br>主从服务器架构可以通过程序或代理软件实现用户的读写分离。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" data-id="ckomwm8uh0000cguh8prs8uqo" data-title="mysql实现主从同步" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/mysql/" rel="tag">mysql</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-CentOS部署flask项目" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/" class="article-date">
  <time class="dt-published" datetime="2021-05-08T16:00:00.000Z" itemprop="datePublished">2021-05-09</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/">nginx部署flask项目</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="Flask部署"><a href="#Flask部署" class="headerlink" title="Flask部署"></a>Flask部署</h3><h4 id="1、编写基本配置"><a href="#1、编写基本配置" class="headerlink" title="1、编写基本配置"></a>1、编写基本配置</h4><p>Flask部署 可以参考 Django的部署过程，我们根据Django理论，Flask框架也支持WSGI协议，则也可以使用uWsgi服务器来作为web应用服务器。</p>
<p>我们只需要修改ini配置文件</p>
<p>需要进入项目下进行环境的打包</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip freeze &gt; requirement.txt</span><br></pre></td></tr></table></figure>
<p>由于需要wsgi协议来配置应用服务器，我们需要新建一个uwsgi.ini文件配置服务器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[uwsgi]</span><br><span class="line">socket = 172.24.10.233:3030     #用来映射的端口</span><br><span class="line">chdir = /home/flask_nginx/Students/     #项目根目录路径</span><br><span class="line">wsgi-file = Students/main.py        #项目文件路径</span><br><span class="line">callable = app  # 这里需要app</span><br><span class="line">processes = 4   # 开启的进程数</span><br><span class="line">threads = 2     # 线程数</span><br></pre></td></tr></table></figure>
<h4 id="2、云主机运行测试"><a href="#2、云主机运行测试" class="headerlink" title="2、云主机运行测试"></a>2、云主机运行测试</h4><p>与django一样，创建一个专属于flask项目的文件夹，来存放你的flask项目</p>
<p>我的是在云主机的home目录下创建</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir flask_nginx</span><br></pre></td></tr></table></figure>
<p>我们把项目通过filezilla本地连接云主机传入项目到flask_nginx目录下</p>
<p>之后下载所需要的环境</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip3 install -r requirement.txt</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">export FLASK_APP=main.py  # 指定flask项目运行文件</span><br><span class="line">flask run  --host=0.0.0.0   # 启动项目</span><br></pre></td></tr></table></figure>
<p>项目运行没问题后就可以部署flask了</p>
<h4 id="3、项目映射nginx"><a href="#3、项目映射nginx" class="headerlink" title="3、项目映射nginx"></a>3、项目映射nginx</h4><p>我们首先进入nginx目录配置下</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd /usr/local/nginx/conf/conf # 这是我存放一些配置文件的目录</span><br></pre></td></tr></table></figure>
<p>在nginx.conf主配置中导入所有子配置(如果已经配置请忽略此步骤)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include /usr/local/nginx/conf/conf/*.conf;</span><br></pre></td></tr></table></figure>
<p>cd 进入新建的conf中配置flask.conf</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd conf</span><br><span class="line"></span><br><span class="line">vi flask.conf</span><br></pre></td></tr></table></figure>

<p>在flask.conf中做以下配置</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen       5000;    # 端口监听5000,(可以自由设置，但请确保该端口的防火墙已开启)</span><br><span class="line">    server_name  localhost;</span><br><span class="line"></span><br><span class="line">    #charset koi8-r;</span><br><span class="line">    #access_log  /var/log/nginx/host.access.log  main;</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line">       include  uwsgi_params;</span><br><span class="line">       uwsgi_pass 172.24.10.233:3030;   # 映射端口，要与配置内网IP和端口一致</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    #error_page  404              /404.html;</span><br><span class="line"></span><br><span class="line">    # redirect server error pages to the static page /50x.html</span><br><span class="line">    #</span><br><span class="line">    error_page   500 502 503 504  /50x.html;</span><br><span class="line">    location = /50x.html &#123;</span><br><span class="line">        root   /usr/share/nginx/html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>完成后进入项目的uwsgi.ini配置的目录，重启</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uwsgi --ini uwsgi.ini &amp;</span><br></pre></td></tr></table></figure>
<p>重启nginx服务</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart nginx</span><br></pre></td></tr></table></figure>
<h4 id="4、补充"><a href="#4、补充" class="headerlink" title="4、补充"></a>4、补充</h4><p>由于我在前端访问我的flask项目会出现一个错误</p>
<p><strong>RuntimeError: cryptography is required for sha256_password or caching_sha2_password</strong></p>
<p>于是我又安装了cryptography</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip3 install cryptography</span><br></pre></td></tr></table></figure>
<p>nice！这个问题成功解决了</p>
<hr>
<p>最后如果要更改数据库的配置不要忘了将你的flask项目的settings文件更改你要使用的数据库</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/" data-id="ckoh4ydos0000nouhfucc9co3" data-title="nginx部署flask项目" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-docker的使用" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/23/docker%E7%9A%84%E4%BD%BF%E7%94%A8/" class="article-date">
  <time class="dt-published" datetime="2021-04-22T16:00:00.000Z" itemprop="datePublished">2021-04-23</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/23/docker%E7%9A%84%E4%BD%BF%E7%94%A8/">docker的使用</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="一、Docker介绍"><a href="#一、Docker介绍" class="headerlink" title="一、Docker介绍"></a>一、Docker介绍</h1><h2 id="1、Docker介绍"><a href="#1、Docker介绍" class="headerlink" title="1、Docker介绍"></a>1、Docker介绍</h2><p>Docker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E9%95%9C%E5%83%8F/1574">镜像</a>中，然后发布到任何流行的 <a target="_blank" rel="noopener" href="https://baike.baidu.com/item/Linux">Linux</a>或<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/Windows/165458">Windows</a> 机器上，也可以实现<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E8%99%9A%E6%8B%9F%E5%8C%96/547949">虚拟化</a>。容器是完全使用<a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%B2%99%E7%AE%B1/393318">沙箱</a>机制，相互之间不会有任何接口。</p>
<p>一个完整的Docker有以下几个部分组成：</p>
<ol>
<li>DockerClient客户端    –客户端</li>
<li>Docker Daemon守护进程  –服务端</li>
<li>Docker Image镜像</li>
<li>DockerContainer容器 </li>
</ol>
<h2 id="Docker架构"><a href="#Docker架构" class="headerlink" title="Docker架构"></a>Docker架构</h2><p>Docker使用客户端-服务器架构。Docker<em>客户端</em>与Docker<em>守护进程</em>进行对话，该<em>守护进程</em>完成了构建，运行和分发Docker容器的繁重工作。Docker客户端和守护程序<em>可以</em> 在同一系统上运行，或者您可以将Docker客户端连接到远程Docker守护程序。Docker客户端和守护程序在UNIX套接字或网络接口上使用REST API进行通信。另一个Docker客户端是Docker Compose，它使您可以处理由一组容器组成的应用程序。</p>
<p><img src="https://docs.docker.com/engine/images/architecture.svg" alt="Docker架构图"></p>
<h3 id="Docker守护程序"><a href="#Docker守护程序" class="headerlink" title="Docker守护程序"></a>Docker守护程序</h3><p>Docker守护程序（<code>dockerd</code>）侦听Docker API请求并管理Docker对象，例如图像，容器，网络和卷。守护程序还可以与其他守护程序通信以管理Docker服务。</p>
<h3 id="Docker客户端"><a href="#Docker客户端" class="headerlink" title="Docker客户端"></a>Docker客户端</h3><p>Docker客户端（<code>docker</code>）是许多Docker用户与Docker交互的主要方式。当您使用诸如之类的命令时<code>docker run</code>，客户端会将这些命令发送到<code>dockerd</code>，以执行这些命令。该<code>docker</code>命令使用Docker API。Docker客户端可以与多个守护程序通信。</p>
<h3 id="Docker注册表"><a href="#Docker注册表" class="headerlink" title="Docker注册表"></a>Docker注册表</h3><p>Docker<em>注册表</em>存储Docker映像。Docker Hub是任何人都可以使用的公共注册表，并且默认情况下，Docker已配置为在Docker Hub上查找映像。您甚至可以运行自己的私人注册表。</p>
<p>使用<code>docker pull</code>或<code>docker run</code>命令时，将从配置的注册表中提取所需的图像。使用该<code>docker push</code>命令时，会将映像推送到已配置的注册表。</p>
<h3 id="Docker对象"><a href="#Docker对象" class="headerlink" title="Docker对象"></a>Docker对象</h3><p>使用Docker时，您正在创建和使用映像，容器，网络，卷，插件和其他对象。本节是其中一些对象的简要概述。</p>
<h1 id="二、Docker安装"><a href="#二、Docker安装" class="headerlink" title="二、Docker安装"></a>二、Docker安装</h1><h2 id="1、安装"><a href="#1、安装" class="headerlink" title="1、安装"></a>1、安装</h2><p>在新主机上首次安装Docker Engine之前，需要设置Docker存储库。之后，您可以从存储库安装和更新Docker。</p>
<h3 id="1-1-准备工具"><a href="#1-1-准备工具" class="headerlink" title="1.1 准备工具"></a>1.1 准备工具</h3><p>先安装yum工具命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y yum-utils</span><br></pre></td></tr></table></figure>


<p>然后 添加docker的仓库 repo</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum-config-manager \</span><br><span class="line">    --add-repo \</span><br><span class="line">    https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo</span><br></pre></td></tr></table></figure>


<h3 id="1-2-安装docker引擎"><a href="#1-2-安装docker引擎" class="headerlink" title="1.2 安装docker引擎"></a>1.2 安装docker引擎</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install docker-ce docker-ce-cli containerd.io</span><br></pre></td></tr></table></figure>




<h3 id="1-3-启动Docker服务"><a href="#1-3-启动Docker服务" class="headerlink" title="1.3 启动Docker服务"></a>1.3 启动Docker服务</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure>


<h3 id="1-4-测试docker"><a href="#1-4-测试docker" class="headerlink" title="1.4 测试docker"></a>1.4 测试docker</h3><p>从Docker Hub网站上 拉取一个 hello-world镜像 然后运行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run hello-world</span><br></pre></td></tr></table></figure>


<h1 id="三、镜像Image"><a href="#三、镜像Image" class="headerlink" title="三、镜像Image"></a>三、镜像Image</h1><p>镜像就类似于一个软件，我们运行就创建了一个容器。</p>
<p>基本命令格式：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker 命令</span><br></pre></td></tr></table></figure>
<h2 id="3-1-基础命令"><a href="#3-1-基础命令" class="headerlink" title="3.1 基础命令"></a>3.1 基础命令</h2><p>查看本地镜像列表</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images ls</span><br></pre></td></tr></table></figure>


<h3 id="1、查看本地镜像"><a href="#1、查看本地镜像" class="headerlink" title="1、查看本地镜像"></a>1、查看本地镜像</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>


<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# docker images</span><br><span class="line"></span><br><span class="line">REPOSITORY                 TAG            IMAGE ID       CREATED         SIZE</span><br><span class="line"></span><br><span class="line">nginx                      latest         08393e824c32   8 months ago    132MB</span><br><span class="line">mysql                      5.6            1d3d3845393d   8 months ago    302MB</span><br><span class="line">mysql                      latest         0d64f46acfd1   8 months ago    544MB</span><br><span class="line">centos                     7              b5b4d78bc90c   11 months ago   203MB</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>解释：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">REPOSITORY：表示镜像的仓库源</span><br><span class="line"></span><br><span class="line">TAG：镜像的标签</span><br><span class="line"></span><br><span class="line">IMAGE ID：镜像ID</span><br><span class="line"></span><br><span class="line">CREATED：镜像创建时间</span><br><span class="line"></span><br><span class="line">SIZE：镜像大小</span><br><span class="line">同一仓库源可以有多个 TAG，代表这个仓库源的不同个版本，如 ubuntu 仓库源里，有 15.10、14.04 等多个不同的版本，我们使用 REPOSITORY:TAG 来定义不同的镜像。</span><br></pre></td></tr></table></figure>


<h3 id="2、拉取镜像"><a href="#2、拉取镜像" class="headerlink" title="2、拉取镜像"></a>2、拉取镜像</h3><p>我们的镜像都可以存放到Docker Hub网站(gitee码云)上，这是一个开源的镜像库</p>
<p>如果从这个网站上 下载东西 就可以使用 pull 拉取  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker pull </span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 下载mysql,下面两条语句都可以</span></span><br><span class="line">docker image pull mysql:5.7</span><br><span class="line"></span><br><span class="line">docker pull mysql:5.7</span><br></pre></td></tr></table></figure>
<p>如果没有添加版本tag 则下载默认的最新版本 mysql:latest</p>
<h3 id="3、删除镜像"><a href="#3、删除镜像" class="headerlink" title="3、删除镜像"></a>3、删除镜像</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi 镜像名</span><br></pre></td></tr></table></figure>


<p>如果 镜像被容器在使用，默认是不能删除的，可以通过 -f 强制删除</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi hello-world</span><br></pre></td></tr></table></figure>


<h1 id="四、容器Container"><a href="#四、容器Container" class="headerlink" title="四、容器Container"></a>四、容器Container</h1><h2 id="4-1-基础命令"><a href="#4-1-基础命令" class="headerlink" title="4.1 基础命令"></a>4.1 基础命令</h2><h3 id="1、运行容器"><a href="#1、运行容器" class="headerlink" title="1、运行容器"></a>1、运行容器</h3><p>在本地 如果有镜像 就可以运行该镜像 生成容器，如果镜像不存在 会去网上pull后在运行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">docker run 镜像名</span><br><span class="line"></span><br><span class="line">--name  在启动的时候 给容器 起一个名字</span><br><span class="line"></span><br><span class="line">--interactive , -i		交互</span><br><span class="line">--tty , -t      终端</span><br><span class="line">这两个一般都是一起用 -it</span><br><span class="line"></span><br><span class="line">-d 执行的容器 不会直接开启交互</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker  run --name  myhello hello-world</span><br></pre></td></tr></table></figure>
<p>交互式启动容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name mycentos -it centos:7 </span><br></pre></td></tr></table></figure>




<h3 id="2、查看容器列表"><a href="#2、查看容器列表" class="headerlink" title="2、查看容器列表"></a>2、查看容器列表</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker ps  查看 所有活跃的容器</span><br><span class="line"></span><br><span class="line">docker ps -a  查看所有容器 包括停止的</span><br></pre></td></tr></table></figure>


<h3 id="3、从容器中提取出镜像"><a href="#3、从容器中提取出镜像" class="headerlink" title="3、从容器中提取出镜像"></a>3、从容器中提取出镜像</h3><p>Create a new image from a container’s changes</p>
<p>如果我们给现有的容器做了修改，而且这个修改以后还要常用，我们就可以提前出镜像，作为一个新的版本</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]</span><br><span class="line"></span><br><span class="line"># 案例</span><br><span class="line">docker  commit -a &quot;刘某人&quot; -m &quot;看你不爽,修改一下&quot;  d62332d7bf22  mycentos:7.1</span><br></pre></td></tr></table></figure>
<p>查看本地镜像列表</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost jiyun]# docker images</span><br><span class="line">REPOSITORY                 TAG            IMAGE ID       CREATED          SIZE</span><br><span class="line">mycentos                   7.1            c415d57cbff4   15 seconds ago   227MB</span><br><span class="line">&lt;none&gt;                     &lt;none&gt;         9924749400a6   13 hours ago     314MB</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h3 id="4、镜像推送-仓库"><a href="#4、镜像推送-仓库" class="headerlink" title="4、镜像推送 仓库"></a>4、镜像推送 仓库</h3><p>1、给镜像打包tag</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]</span><br><span class="line"></span><br><span class="line"># 案例</span><br><span class="line"></span><br><span class="line">docker tag mycentos:7.1 xiaozhuanjia&#x2F;mycentos:7.1</span><br></pre></td></tr></table></figure>
<p>2、推送</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker push [OPTIONS] NAME[:TAG]</span><br><span class="line"></span><br><span class="line"># 案例</span><br><span class="line">docker push xiaozhuanjia&#x2F;mycentos:7.1</span><br></pre></td></tr></table></figure>




<h3 id="5、启动常见服务容器"><a href="#5、启动常见服务容器" class="headerlink" title="5、启动常见服务容器"></a>5、启动常见服务容器</h3><p>如果想要容器 长时间运行 作为服务，需要加-d 后台运行 </p>
<p>-d执行的容器 不会直接开启交互</p>
<p>我们需要使用 docker exec 进入到容器</p>
<p>docker exec -it 1e592c76445b /bin/bash</p>
<h4 id="5-1-启动redis"><a href="#5-1-启动redis" class="headerlink" title="5.1  启动redis"></a>5.1  启动redis</h4><p>-p   端口号的映射    宿主机端口:容器端口</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">docker run -itd -p 6379:6379 redis   </span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 还可以继续开 开多个</span></span><br><span class="line">docker run -itd -p 6378:6379 redis</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> redis启动进入容器</span></span><br><span class="line">redis-cli -h 127.0.0.1 -p 6378</span><br></pre></td></tr></table></figure>


<h4 id="5-2-开启mysql"><a href="#5-2-开启mysql" class="headerlink" title="5.2 开启mysql"></a>5.2 开启mysql</h4><p>和普通开发服务一样，但也有特定， 需要知道 账号 密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name mysql57 -itd  -p 3305:3306 -e MYSQL_ROOT_PASSWORD&#x3D;Guo_1234 mysql:5.7</span><br></pre></td></tr></table></figure>


<p>进入到mysql容器服务里</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it 容器id /bin/bash</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 之后执行用户登录就能成功进入mysql进行操作了</span></span><br><span class="line">mysql -u root -p</span><br><span class="line">enterpassword：你的密码</span><br></pre></td></tr></table></figure>
<p>然后可以操作数据库，进行数据库的增删改查操作</p>
<h3 id="6、Dockerfile使用"><a href="#6、Dockerfile使用" class="headerlink" title="6、Dockerfile使用"></a>6、Dockerfile使用</h3><p>如果我们想从零开始构建镜像，例如我们把我们的django项目 或者vue项目 作为一个镜像供其他人使用</p>
<p>可以使用Dockerfile文件来 描述这个镜像的构建过程。</p>
<h4 id="6-1-基础命令"><a href="#6-1-基础命令" class="headerlink" title="6.1 基础命令"></a>6.1 基础命令</h4><p><strong>FROM</strong>  定制的镜像都是基于 FROM 的镜像</p>
<p><strong>RUN</strong>：用于执行后面跟着的命令行命令   在执行 docker build 会执行该命令</p>
<p><strong>COPY</strong>: 拷贝复制文件</p>
<p><strong>CMD</strong> :  在docker run的时候会 执行 这里的命令</p>
<h4 id="6-2-给django项目写文件"><a href="#6-2-给django项目写文件" class="headerlink" title="6.2 给django项目写文件"></a>6.2 给django项目写文件</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 生成一个django项目的镜像</span><br><span class="line">FROM 3.6-alpine</span><br><span class="line">COPY requirement.txt  .</span><br><span class="line">RUN  pip3 install -r requirement.txt</span><br><span class="line">COPY hellopro .</span><br><span class="line">CMD [&quot;python3&quot;,&quot;manage.py&quot;,&quot;runserver&quot;]</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><strong>完成后使用docker build来生成镜像</strong></p>
<p>在 Dockerfile 文件的存放目录下，执行构建动作。</p>
<p>以下示例，通过目录下的 Dockerfile 构建一个 django/v1（镜像名称:镜像标签)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build -t django/v1 .</span><br></pre></td></tr></table></figure>

















      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/23/docker%E7%9A%84%E4%BD%BF%E7%94%A8/" data-id="cknucg22a000058uh8rnn7e5u" data-title="docker的使用" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/docker/" rel="tag">docker</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-CentOS部署django项目" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/22/CentOS%E9%83%A8%E7%BD%B2django%E9%A1%B9%E7%9B%AE/" class="article-date">
  <time class="dt-published" datetime="2021-04-21T16:00:00.000Z" itemprop="datePublished">2021-04-22</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/22/CentOS%E9%83%A8%E7%BD%B2django%E9%A1%B9%E7%9B%AE/">nginx部署django项目</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="整体流程共分为nginx部署django和nginx部署vue"><a href="#整体流程共分为nginx部署django和nginx部署vue" class="headerlink" title="整体流程共分为nginx部署django和nginx部署vue"></a>整体流程共分为nginx部署django和nginx部署vue</h2><p><img src="https://i.loli.net/2021/04/28/jOLc8UglmKSrQMD.png" alt="部署项目流程.png"></p>
<h3 id="django项目配置"><a href="#django项目配置" class="headerlink" title="django项目配置"></a>django项目配置</h3><p>在settings.py文件中配置</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">DEBUG = <span class="literal">True</span> <span class="comment"># 暂时开着</span></span><br><span class="line"></span><br><span class="line">ALLOWED_HOSTS = [<span class="string">&#x27;*&#x27;</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置静态资源目录，后面部署会用到 </span></span><br><span class="line">STATIC_ROOT = os.path.join(BASE_DIR, <span class="string">&quot;static&quot;</span>)</span><br></pre></td></tr></table></figure>
<h3 id="将django项目中所需要的环境进行打包"><a href="#将django项目中所需要的环境进行打包" class="headerlink" title="将django项目中所需要的环境进行打包"></a>将django项目中所需要的环境进行打包</h3><p>需要进入项目下进行环境的打包</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip freeze &gt; requirement.txt</span><br></pre></td></tr></table></figure>
<p>效果图<br><img src="https://i.loli.net/2021/04/22/g9kImitHxG6yalp.png" alt="打包requirement.png"></p>
<p>可以使用filezilla上传到CentOS云主机上,p8_workorder为我的项目<br><img src="https://i.loli.net/2021/04/22/VRDHB1WQgzOxL3U.png" alt="上传项目到云主机.png"></p>
<p>cd进入到我的项目目录中</p>
<h3 id="安装所需要的环境与配置uwsgi"><a href="#安装所需要的环境与配置uwsgi" class="headerlink" title="安装所需要的环境与配置uwsgi"></a>安装所需要的环境与配置uwsgi</h3><p>安装所需要的环境</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 如果你的安装是pip请使用pip安装，我的是pip3</span></span><br><span class="line">pip3 install -r requirement.txt</span><br></pre></td></tr></table></figure>
<p>我们还需要uwsgi协议进行后续的部署，但是直接安装uwsgi会报异常</p>
<p>我们需要yum安装相应的配置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum install -y gcc* pcre-devel openssl-devel</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 根据你安装python的名称来决定安装，比如我启动python是用python3来启动，所以我的安装是这样的</span></span><br><span class="line">yum install python3-devel -y</span><br></pre></td></tr></table></figure>
<p>现在我们就可以安装uwsgi协议了</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip3 install uwsgi</span><br></pre></td></tr></table></figure>
<p>接下来我们需要执行命令来覆盖我们配置的静态资源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python3 manage.py collectstatic</span><br></pre></td></tr></table></figure>
<p>接下来创建一个conf目录来存放我们的django部署配置文件</p>
<p><img src="https://i.loli.net/2021/04/23/tJn4gIufy19DKEC.png" alt="静态资源和配置.png"></p>
<p>后续会把static静态目录的资源部署到nginx上，先不急，先写配置文件</p>
<p>cd进入conf开始编写配置文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi uwsgi.ini</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[uwsgi]</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> http = 192.168.12.214:8000</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 我是使用socket进行端口映射，映射到django的配置文件上(ip是我内网的IP，用来做端口映射)</span></span><br><span class="line">socket = 172.24.10.233:8800</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 我的项目根目录位置，如果不知道具体位置可以在项目根目录进行<span class="built_in">pwd</span>查看</span></span><br><span class="line">chdir = /home/django_nginx/p8_workorder/</span><br><span class="line"></span><br><span class="line">wsgi-file = p8_workorder/wsgi.py</span><br><span class="line"><span class="meta">#</span><span class="bash"> 主线程开启</span></span><br><span class="line">master = true</span><br><span class="line"><span class="meta">#</span><span class="bash"> 开启进程的个数</span></span><br><span class="line">processes = 2</span><br><span class="line"><span class="meta">#</span><span class="bash"> 线程个数</span></span><br><span class="line">threads = 2</span><br><span class="line"><span class="meta">#</span><span class="bash"> 日志文件所在位置</span></span><br><span class="line">logto = /home/django_nginx/p8_workorder/conf/worker.log</span><br><span class="line"><span class="meta">#</span><span class="bash"> 文件位置同上</span></span><br><span class="line">pidfile = /home/django_nginx/p8_workorder/conf/worker.pid</span><br><span class="line"></span><br><span class="line">buffer-size = 65536</span><br></pre></td></tr></table></figure>
<p>完成之后启动uwsgi查看</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uwsgi --ini uwsgi.ini</span><br></pre></td></tr></table></figure>
<p>浏览器访问ip和端口进行查看</p>
<h3 id="nginx部署静态资源及django配置"><a href="#nginx部署静态资源及django配置" class="headerlink" title="nginx部署静态资源及django配置"></a>nginx部署静态资源及django配置</h3><p>我们需要把刚才的static静态目录部署到nginx.conf中,首先进入我nginx.conf所在目录下<br>由于我的nginx是使用源码wget安装的，yum安装则需要到/etc目录下去找<br><img src="https://i.loli.net/2021/04/23/AXz3fZLlv4TiatS.png" alt="进入nginx.png"></p>
<p>我是在conf目录下又创建了一个conf目录，用来存放django.conf配置的，所以我在nginx.conf<br>中写了这条语句,如果使用yum安装的nginx请忽略此步骤</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include /usr/local/nginx/conf/conf/*.conf;</span><br></pre></td></tr></table></figure>
<p>cd 进入新建的conf中配置django.conf</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd conf</span><br><span class="line"></span><br><span class="line">vi django.conf</span><br></pre></td></tr></table></figure>
<p>在django.conf中做以下配置</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">upstream fanxiang&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 配置负载均衡，此处为django配置uwsgi映射的端口，与uwsgi中映射端口要一致</span></span><br><span class="line">   server 172.24.10.233:8800;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">server &#123;</span><br><span class="line">    # 监听端口</span><br><span class="line">    listen     8000;</span><br><span class="line">    server_name  localhost;</span><br><span class="line"></span><br><span class="line">    error_page   500 502 503 504  /50x.html;</span><br><span class="line">    location = /50x.html &#123;</span><br><span class="line">        root   /usr/share/nginx/html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line"></span><br><span class="line">      include uwsgi_params; # 使用 uwsgi协议</span><br><span class="line">      uwsgi_pass fanxiang; # 反向代理，配置连接django应用服务器</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    # 此处配置静态目录</span><br><span class="line">    location /static/ &#123;</span><br><span class="line">            # 一种是根路径配置，一种是别名配置，任何一种都可以(不要在语句后注释，可能会导致在同一行注释到后面的配置，从而访问不到静态资源)</span><br><span class="line">            # root /home/django_nginx/p8_workorder;                  </span><br><span class="line">           alias /home/django_nginx/p8_workorder/static/;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>完成后进入项目的uwsgi.ini配置的目录，重启</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uwsgi --ini uwsgi.ini &amp;</span><br></pre></td></tr></table></figure>
<p>重启nginx服务</p>
<figure class="highlight shell"><figcaption><span>script</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart nginx</span><br></pre></td></tr></table></figure>
<h3 id="补充："><a href="#补充：" class="headerlink" title="补充："></a>补充：</h3><h3 id="负载均衡的几种方式"><a href="#负载均衡的几种方式" class="headerlink" title="负载均衡的几种方式"></a>负载均衡的几种方式</h3><h4 id="1、轮询（默认）"><a href="#1、轮询（默认）" class="headerlink" title="1、轮询（默认）"></a>1、轮询（默认）</h4><p>每个请求按时间顺序逐一分配到不同的后端服务器，如果后端服务器down掉，能自动剔除。</p>
<h4 id="2、weight-（权重）"><a href="#2、weight-（权重）" class="headerlink" title="2、weight （权重）"></a>2、weight （权重）</h4><p>按照不同比重进行资源的处理</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">upstream jiyun &#123;</span><br><span class="line"></span><br><span class="line">   server  127.0.0.1:8800 weight&#x3D;1;</span><br><span class="line">   server  127.0.0.1:8801 weight&#x3D;2;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>经过测试，8801接收到的请求个数 比 8800多一倍</p>
<h4 id="3、ipHash进行分配"><a href="#3、ipHash进行分配" class="headerlink" title="3、ipHash进行分配"></a>3、ipHash进行分配</h4><p>通过hash算法来计算处理</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">upstream jiyun &#123;</span><br><span class="line">   ip_hash;</span><br><span class="line">   server 127.0.0.1:8800;</span><br><span class="line">   server 127.0.0.1:8801;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="正向代理与反向代理"><a href="#正向代理与反向代理" class="headerlink" title="正向代理与反向代理"></a>正向代理与反向代理</h3><p><img src="https://img-blog.csdn.net/20170702105958247?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzU1NjgwOTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="正向代理与反向代理"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/22/CentOS%E9%83%A8%E7%BD%B2django%E9%A1%B9%E7%9B%AE/" data-id="cknublgbe0005v8uhcox3f1cz" data-title="nginx部署django项目" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-flask实现图片验证码(未完成)" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/22/flask%E5%AE%9E%E7%8E%B0%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81(%E6%9C%AA%E5%AE%8C%E6%88%90)/" class="article-date">
  <time class="dt-published" datetime="2021-04-21T16:00:00.000Z" itemprop="datePublished">2021-04-22</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/22/flask%E5%AE%9E%E7%8E%B0%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81(%E6%9C%AA%E5%AE%8C%E6%88%90)/">flak实现图片验证码(未完成)</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MakeImgCode</span>(<span class="params">Resource</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self</span>):</span></span><br><span class="line">        req = reqparse.RequestParser()</span><br><span class="line">        req.add_argument(<span class="string">&#x27;key&#x27;</span>)</span><br><span class="line">        args = req.parse_args()</span><br><span class="line">        key = args.get(<span class="string">&#x27;key&#x27;</span>)</span><br><span class="line">        r = Redis(<span class="string">&#x27;localhost&#x27;</span>, <span class="number">6379</span>, decode_responses=<span class="literal">True</span>)</span><br><span class="line">        <span class="comment"># 获取验证码</span></span><br><span class="line">        code, img = CodeUtils.make_code_n()</span><br><span class="line">        <span class="comment"># 获取传过来的uuid</span></span><br><span class="line">        <span class="comment"># 将验证码存入redis数据库, 设置时间为60s</span></span><br><span class="line">        r.<span class="built_in">set</span>(key, code, <span class="number">60</span>)</span><br><span class="line">        resp = make_response(img)</span><br><span class="line">        resp.content_type = <span class="string">&quot;image/jpeg&quot;</span></span><br><span class="line">        <span class="keyword">return</span> resp</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Login</span>(<span class="params">Resource</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self</span>):</span></span><br><span class="line">        req = reqparse.RequestParser()</span><br><span class="line">        req.add_argument(<span class="string">&#x27;account&#x27;</span>)</span><br><span class="line">        req.add_argument(<span class="string">&#x27;password&#x27;</span>)</span><br><span class="line">        req.add_argument(<span class="string">&#x27;code&#x27;</span>)</span><br><span class="line">        req.add_argument(<span class="string">&#x27;key&#x27;</span>)</span><br><span class="line">        args = req.parse_args()</span><br><span class="line">        account = args.get(<span class="string">&#x27;account&#x27;</span>)</span><br><span class="line">        password = args.get(<span class="string">&#x27;password&#x27;</span>)</span><br><span class="line">        code = args.get(<span class="string">&#x27;code&#x27;</span>)</span><br><span class="line">        key = args.get(<span class="string">&#x27;key&#x27;</span>)</span><br><span class="line">        r = Redis(<span class="string">&#x27;localhost&#x27;</span>, <span class="number">6379</span>, decode_responses=<span class="literal">True</span>)</span><br><span class="line">        code_redis = r.get(key)</span><br><span class="line">        user = UsersModel.query.filter_by(account=account).first()</span><br><span class="line">        print(code, code_redis)</span><br><span class="line">        <span class="keyword">if</span> code.lower() != code_redis:</span><br><span class="line">            <span class="keyword">return</span> &#123;<span class="string">&#x27;message&#x27;</span>: <span class="string">&#x27;验证码错误&#x27;</span>&#125;</span><br><span class="line">        <span class="keyword">if</span> user.password == password:</span><br><span class="line">            token = generate_jwt(user.uid)</span><br><span class="line">            <span class="keyword">return</span> &#123;<span class="string">&#x27;message&#x27;</span>: <span class="string">&#x27;登录成功&#x27;</span>, <span class="string">&#x27;token&#x27;</span>: token, <span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>&#125;</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> &#123;<span class="string">&#x27;message&#x27;</span>: <span class="string">&#x27;登录失败&#x27;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">400</span>&#125;</span><br><span class="line"></span><br><span class="line"><span class="number">21</span>:<span class="number">34</span>:<span class="number">00</span></span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">import</span> string</span><br><span class="line"><span class="keyword">from</span> captcha.image <span class="keyword">import</span> ImageCaptcha</span><br><span class="line"><span class="keyword">from</span> io <span class="keyword">import</span> BytesIO</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">CodeUtils</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line"><span class="meta">    @staticmethod</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">make_code_n</span>():</span></span><br><span class="line">        code = <span class="string">&quot;&quot;</span>.join(random.sample(string.digits, <span class="number">4</span>))</span><br><span class="line">        <span class="comment"># 生成图片验证码</span></span><br><span class="line">        img_captcha = ImageCaptcha()</span><br><span class="line">        <span class="comment"># 生成图片</span></span><br><span class="line">        img = img_captcha.generate_image(code)</span><br><span class="line">        <span class="comment"># img.show()</span></span><br><span class="line">        <span class="comment"># 创建一个字节流</span></span><br><span class="line">        bytes_io = BytesIO()</span><br><span class="line">        <span class="comment"># 要把对象存入字节流对象</span></span><br><span class="line">        img.save(bytes_io, <span class="string">&quot;jpeg&quot;</span>)</span><br><span class="line">        <span class="keyword">return</span> code, bytes_io.getvalue()</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/22/flask%E5%AE%9E%E7%8E%B0%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81(%E6%9C%AA%E5%AE%8C%E6%88%90)/" data-id="ckobbowfb0000mcuhbi0m9hvh" data-title="flak实现图片验证码(未完成)" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/Flask/" rel="tag">Flask</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-CentOS上安装mysql" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/" class="article-date">
  <time class="dt-published" datetime="2021-04-20T16:00:00.000Z" itemprop="datePublished">2021-04-21</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/">CentOS上安装mysql</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="安装mysql"><a href="#安装mysql" class="headerlink" title="安装mysql"></a>安装mysql</h2><p>去官网上查看  <a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/repo/yum/">https://dev.mysql.com/downloads/repo/yum/</a>       mysql的yum仓库</p>
<p>这里安装mysql的源</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y https:&#x2F;&#x2F;repo.mysql.com&#x2F;&#x2F;mysql80-community-release-el7-3.noarch.rpm</span><br></pre></td></tr></table></figure>
<p>检查MySQL源是否安装成功</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">yum repolist enabled</span><br><span class="line"></span><br><span class="line">查看结果：</span><br><span class="line">mysql-connectors-community                               | 2.6 kB     00:00     </span><br><span class="line">mysql-tools-community                                    | 2.6 kB     00:00     </span><br><span class="line">mysql80-community                                        | 2.6 kB     00:00     </span><br><span class="line">(1&#x2F;3): mysql-connectors-community&#x2F;x86_64&#x2F;primary_db        |  77 kB   00:01     </span><br><span class="line">(2&#x2F;3): mysql80-community&#x2F;x86_64&#x2F;primary_db                 | 153 kB   00:02     </span><br><span class="line">(3&#x2F;3): mysql-tools-community&#x2F;x86_64&#x2F;primary_db             |  87 kB   00:03     </span><br><span class="line">repo id                           repo name                               status</span><br><span class="line">base&#x2F;7&#x2F;x86_64                     CentOS-7                                10,072</span><br><span class="line">epel&#x2F;x86_64                       Extra Packages for Enterprise Linux 7 - 13,581</span><br><span class="line">extras&#x2F;7&#x2F;x86_64                   CentOS-7                                   468</span><br><span class="line">mysql-connectors-community&#x2F;x86_64 MySQL Connectors Community                 194</span><br><span class="line">mysql-tools-community&#x2F;x86_64      MySQL Tools Community                      126</span><br><span class="line">mysql80-community&#x2F;x86_64          MySQL 8.0 Community Server                 247</span><br><span class="line">updates&#x2F;7&#x2F;x86_64                  CentOS-7                                 1,932</span><br><span class="line">repolist: 26,620</span><br></pre></td></tr></table></figure>


<p>源安装好以后，安装mysql服务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install mysql-community-server</span><br></pre></td></tr></table></figure>
<p>服务开始安装中…，需要安装 Total download size: 553 M，安装期间有yes直接yes</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line">Resolving Dependencies</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-server.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Processing Dependency: mysql-community-common(x86-64) &#x3D; 8.0.24-1.el7 for package: mysql-community-server-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: mysql-community-client(x86-64) &gt;&#x3D; 8.0.11 for package: mysql-community-server-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-client.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Processing Dependency: mysql-community-client-plugins &#x3D; 8.0.24-1.el7 for package: mysql-community-client-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: mysql-community-libs(x86-64) &gt;&#x3D; 8.0.11 for package: mysql-community-client-8.0.24-1.el7.x86_64</span><br><span class="line">---&gt; Package mysql-community-common.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted</span><br><span class="line">--&gt; Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64</span><br><span class="line">---&gt; Package mysql-community-client-plugins.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">---&gt; Package mysql-community-libs.x86_64 0:8.0.24-1.el7 will be obsoleting</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-libs-compat.x86_64 0:8.0.24-1.el7 will be obsoleting</span><br><span class="line">---&gt; Package postfix.x86_64 2:2.10.1-6.el7 will be updated</span><br><span class="line">---&gt; Package postfix.x86_64 2:2.10.1-9.el7 will be an update</span><br><span class="line">--&gt; Finished Dependency Resolution</span><br><span class="line"></span><br><span class="line">Dependencies Resolved</span><br><span class="line"></span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line"> Package                        Arch   Version          Repository         Size</span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line">Installing:</span><br><span class="line"> mysql-community-libs           x86_64 8.0.24-1.el7     mysql80-community 4.0 M</span><br><span class="line">     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7</span><br><span class="line"> mysql-community-libs-compat    x86_64 8.0.24-1.el7     mysql80-community 1.2 M</span><br><span class="line">     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7</span><br><span class="line"> mysql-community-server         x86_64 8.0.24-1.el7     mysql80-community 428 M</span><br><span class="line">Installing for dependencies:</span><br><span class="line"> mysql-community-client         x86_64 8.0.24-1.el7     mysql80-community  45 M</span><br><span class="line"> mysql-community-client-plugins x86_64 8.0.24-1.el7     mysql80-community 189 k</span><br><span class="line"> mysql-community-common         x86_64 8.0.24-1.el7     mysql80-community 614 k</span><br><span class="line">Updating for dependencies:</span><br><span class="line"> postfix                        x86_64 2:2.10.1-9.el7   base              2.4 M</span><br><span class="line"></span><br><span class="line">Transaction Summary</span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line">Install  3 Packages (+3 Dependent packages)</span><br><span class="line">Upgrade             ( 1 Dependent package)</span><br><span class="line"></span><br><span class="line">Total download size: 482 M</span><br><span class="line">Is this ok [y&#x2F;d&#x2F;N]: y</span><br><span class="line">Downloading packages:</span><br><span class="line">Delta RPMs disabled because &#x2F;usr&#x2F;bin&#x2F;applydeltarpm not installed.</span><br><span class="line">warning: &#x2F;var&#x2F;cache&#x2F;yum&#x2F;x86_64&#x2F;7&#x2F;mysql80-community&#x2F;packages&#x2F;mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm: Header V3 DSA&#x2F;SHA1 Signature, key ID 5072e1f5: NOKEY</span><br><span class="line">Public key for mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm is not installed</span><br><span class="line">(1&#x2F;7): mysql-community-client-plugins-8.0.24-1.el7.x86_64. | 189 kB   00:02     </span><br><span class="line">(2&#x2F;7): mysql-community-common-8.0.24-1.el7.x86_64.rpm      | 614 kB   00:02     </span><br><span class="line">(3&#x2F;7): mysql-community-libs-8.0.24-1.el7.x86_64.rpm        | 4.0 MB   00:08     </span><br><span class="line">(4&#x2F;7): mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm | 1.2 MB   00:03     </span><br><span class="line">(5&#x2F;7): postfix-2.10.1-9.el7.x86_64.rpm                     | 2.4 MB   00:00     </span><br><span class="line">(6&#x2F;7): mysql-community-client-8.0.24-1.el7.x86_64.rpm      |  45 MB   01:15     </span><br><span class="line">(7&#x2F;7): mysql-community-server-8.0.24-1.el7.x86_64.rpm      | 428 MB   11:18     </span><br><span class="line">--------------------------------------------------------------------------------</span><br><span class="line">Total                                              709 kB&#x2F;s | 482 MB  11:35     </span><br><span class="line">Retrieving key from file:&#x2F;&#x2F;&#x2F;etc&#x2F;pki&#x2F;rpm-gpg&#x2F;RPM-GPG-KEY-mysql</span><br><span class="line">Importing GPG key 0x5072E1F5:</span><br><span class="line"> Userid     : &quot;MySQL Release Engineering &lt;mysql-build@oss.oracle.com&gt;&quot;</span><br><span class="line"> Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5</span><br><span class="line"> Package    : mysql80-community-release-el7-3.noarch (installed)</span><br><span class="line"> From       : &#x2F;etc&#x2F;pki&#x2F;rpm-gpg&#x2F;RPM-GPG-KEY-mysql</span><br><span class="line">Is this ok [y&#x2F;N]: y</span><br><span class="line">Running transaction check</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded</span><br><span class="line">Running transaction</span><br><span class="line">  Installing : mysql-community-client-plugins-8.0.24-1.el7.x86_64           1&#x2F;9 </span><br><span class="line">  Installing : mysql-community-common-8.0.24-1.el7.x86_64                   2&#x2F;9 </span><br><span class="line">  Installing : mysql-community-libs-8.0.24-1.el7.x86_64                     3&#x2F;9 </span><br><span class="line">  Installing : mysql-community-client-8.0.24-1.el7.x86_64                   4&#x2F;9 </span><br><span class="line">  Installing : mysql-community-libs-compat-8.0.24-1.el7.x86_64              5&#x2F;9 </span><br><span class="line">  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                6&#x2F;9 </span><br><span class="line">  Installing : mysql-community-server-8.0.24-1.el7.x86_64                   7&#x2F;9 </span><br><span class="line">  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                8&#x2F;9 </span><br><span class="line">  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-server-8.0.24-1.el7.x86_64                   1&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-client-8.0.24-1.el7.x86_64                   2&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-common-8.0.24-1.el7.x86_64                   3&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-libs-compat-8.0.24-1.el7.x86_64              4&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-libs-8.0.24-1.el7.x86_64                     5&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-client-plugins-8.0.24-1.el7.x86_64           6&#x2F;9 </span><br><span class="line">  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                7&#x2F;9 </span><br><span class="line">  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                8&#x2F;9 </span><br><span class="line">  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9&#x2F;9 </span><br><span class="line"></span><br><span class="line">Installed:</span><br><span class="line">  mysql-community-libs.x86_64 0:8.0.24-1.el7                                    </span><br><span class="line">  mysql-community-libs-compat.x86_64 0:8.0.24-1.el7                             </span><br><span class="line">  mysql-community-server.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line"></span><br><span class="line">Dependency Installed:</span><br><span class="line">  mysql-community-client.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line">  mysql-community-client-plugins.x86_64 0:8.0.24-1.el7                          </span><br><span class="line">  mysql-community-common.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line"></span><br><span class="line">Dependency Updated:</span><br><span class="line">  postfix.x86_64 2:2.10.1-9.el7                                                 </span><br><span class="line"></span><br><span class="line">Replaced:</span><br><span class="line">  mariadb-libs.x86_64 1:5.5.52-1.el7                                            </span><br><span class="line"></span><br><span class="line">Complete!</span><br></pre></td></tr></table></figure>
<p>MySQL服务操作</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 启动服务</span><br><span class="line">systemctl start mysqld</span><br><span class="line"></span><br><span class="line"># 查看服务</span><br><span class="line">systemctl status mysqld</span><br></pre></td></tr></table></figure>
<p>修改 MySQL 中 root 本地登录密码</p>
<p>先在日志中查找 生成的密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">grep &#39;temporary password&#39; &#x2F;var&#x2F;log&#x2F;mysqld.log</span><br><span class="line"></span><br><span class="line"># 查看结果</span><br><span class="line">2021-04-21T13:12:52.469425Z 6 [Note] [MY-010454] [Server]</span><br><span class="line">A temporary password is generated for root@localhost: CwPfkidp2m+s  #最后这一串为初始密码</span><br></pre></td></tr></table></figure>


<p>使用密码root登录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p</span><br></pre></td></tr></table></figure>
<p>不过进行其他操作的时候，会发现 提示你用alert 语句去修改密码，这个密码只是临时密码。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; use mysql</span><br><span class="line">ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.</span><br></pre></td></tr></table></figure>


<p>修改root用户密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;Guo_1234&#39;; #密码开头必须大写，必须有下划线</span><br></pre></td></tr></table></figure>

<p>退出mysql</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+Z</span><br></pre></td></tr></table></figure>


<p>修改密码策略</p>
<p>在/etc/my.cnf文件添加validate_password_policy配置，指定密码策略<br>选择0（LOW），1（MEDIUM），2（STRONG）其中一种，选择2需要提供密码字典文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">validate_password_policy&#x3D;0</span><br></pre></td></tr></table></figure>
<p>如果不需要密码策略，添加my.cnf文件中添加如下配置禁用即可：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">validate_password &#x3D; off</span><br></pre></td></tr></table></figure>


<p>重新启动mysql服务使配置生效：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart mysqld</span><br></pre></td></tr></table></figure>


<p>允许远程登录</p>
<p>MySQL默认只允许root帐户在本地登录，想要远程连接MySQL，必须开启root用户允许远程连接，或者添加一个允许远程连接的帐户。</p>
<p>首先查看mysql的 user表</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">select * from user \G</span><br><span class="line"></span><br><span class="line">*************************** 4. row ***************************</span><br><span class="line">                    Host: localhost</span><br><span class="line">                    User: root</span><br><span class="line">             Select_priv: Y</span><br><span class="line">             Insert_priv: Y</span><br><span class="line">             Update_priv: Y</span><br><span class="line">             Delete_priv: Y</span><br><span class="line">             Create_priv: Y</span><br><span class="line">               Drop_priv: Y</span><br><span class="line">             Reload_priv: Y</span><br><span class="line">           Shutdown_priv: Y</span><br><span class="line">            Process_priv: Y</span><br><span class="line">               File_priv: Y</span><br><span class="line">              Grant_priv: Y</span><br><span class="line">         References_priv: Y</span><br><span class="line">              Index_priv: Y</span><br><span class="line">              Alter_priv: Y</span><br><span class="line">            Show_db_priv: Y</span><br><span class="line">              Super_priv: Y</span><br><span class="line">   Create_tmp_table_priv: Y</span><br><span class="line">        Lock_tables_priv: Y</span><br><span class="line">            Execute_priv: Y</span><br><span class="line">         Repl_slave_priv: Y</span><br><span class="line">        Repl_client_priv: Y</span><br><span class="line">        Create_view_priv: Y</span><br><span class="line">          Show_view_priv: Y</span><br><span class="line">     Create_routine_priv: Y</span><br><span class="line">      Alter_routine_priv: Y</span><br><span class="line">        Create_user_priv: Y</span><br><span class="line">              Event_priv: Y</span><br><span class="line">            Trigger_priv: Y</span><br><span class="line">  Create_tablespace_priv: Y</span><br><span class="line">                ssl_type:</span><br><span class="line">              ssl_cipher: 0x</span><br><span class="line">             x509_issuer: 0x</span><br><span class="line">            x509_subject: 0x</span><br><span class="line">           max_questions: 0</span><br><span class="line">             max_updates: 0</span><br><span class="line">         max_connections: 0</span><br><span class="line">    max_user_connections: 0</span><br><span class="line">                  plugin: caching_sha2_password</span><br><span class="line">   authentication_string: $A$005$QVf&#96;</span><br><span class="line">hi@? _:w.FDDatpHPPpgl.7j830gDg9X.HbKF05PzcdmXptHuD</span><br><span class="line">        password_expired: N</span><br><span class="line">   password_last_changed: 2020-08-03 20:01:07</span><br><span class="line">       password_lifetime: NULL</span><br><span class="line">          account_locked: N</span><br><span class="line">        Create_role_priv: Y</span><br><span class="line">          Drop_role_priv: Y</span><br><span class="line">  Password_reuse_history: NULL</span><br><span class="line">     Password_reuse_time: NULL</span><br><span class="line">Password_require_current: NULL</span><br><span class="line">         User_attributes: NULL</span><br><span class="line">4 rows in set (0.01 sec)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>可以看到 root用户默认只能访问localhost   也就是只能本地登录，不能远程登录。</p>
<p>查询mysql具体版本</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">SELECT @@VERSION</span><br><span class="line"></span><br><span class="line">mysql&gt; select @@VERSION;</span><br><span class="line">+-----------+</span><br><span class="line">| @@VERSION |</span><br><span class="line">+-----------+</span><br><span class="line">| 8.0.21    |</span><br><span class="line">+-----------+</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>创建可以远程访问的root用户</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">create user &#39;root&#39;@&#39;%&#39; identified by  &#39;Guo_1234&#39;;</span><br></pre></td></tr></table></figure>
<p>给远程root用户赋予权限</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grant all privileges on *.* to &#39;root&#39;@&#39;%&#39; with grant option;</span><br></pre></td></tr></table></figure>
<p>操作后要执行刷新，远程用户才能有效</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/" data-id="cknublgb80001v8uh3r9y9fdc" data-title="CentOS上安装mysql" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-CentOS中安装nginx" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/20/CentOS%E4%B8%AD%E5%AE%89%E8%A3%85nginx/" class="article-date">
  <time class="dt-published" datetime="2021-04-19T16:00:00.000Z" itemprop="datePublished">2021-04-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/20/CentOS%E4%B8%AD%E5%AE%89%E8%A3%85nginx/">CentOS中安装nginx</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h1><p>我们可以使用两种安装：</p>
<p>1.对源码的 编译–生成编译包–》wget安装</p>
<p>2.预编译包–》yum安装</p>
<h3 id="1-源码安装"><a href="#1-源码安装" class="headerlink" title="1.源码安装"></a>1.源码安装</h3><ul>
<li>第一步 </li>
</ul>
<p>Linux上下载文件，Linux有下载工具wget</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http:&#x2F;&#x2F;nginx.org&#x2F;download&#x2F;nginx-1.18.0.tar.gz</span><br></pre></td></tr></table></figure>
<p>可以从nginx官网上安装的稳定版，通常为1.18.0版本，通过filezilla连接CentOS把压缩包导入自己管理的目录下</p>
<ul>
<li>第二步  解压缩包</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar zxvf nginx-1.18.0.tar.gz</span><br></pre></td></tr></table></figure>
<ul>
<li>第三步 生成makefile文件</li>
</ul>
<p>cd进入到解压包目录</p>
<p>源码安装通常为/usr/local/nginx目录下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure --prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;nginx</span><br></pre></td></tr></table></figure>
<p>这一步一般用来生成 Makefile，为下一步的编译做准备，，一般就使用 参数–prefix ，用来指定安装目录，表示安装到/usr/local/nginx目录下</p>
<ul>
<li>第四步  编译</li>
</ul>
<p>这一步就是编译，大多数的源代码包都经过这一步进行编译</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make</span><br></pre></td></tr></table></figure>
<ul>
<li>第五步 安装</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make install</span><br></pre></td></tr></table></figure>

<h3 id="2-预编译包"><a href="#2-预编译包" class="headerlink" title="2.预编译包"></a>2.预编译包</h3><p>官方提供的 源的配置    <a target="_blank" rel="noopener" href="http://nginx.org/en/linux_packages.html#RHEL-CentOS">http://nginx.org/en/linux_packages.html#RHEL-CentOS</a></p>
<p>步骤1: 安装先决条件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum  install yum-utils</span><br></pre></td></tr></table></figure>
<p>步骤2：创建源文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi &#x2F;etc&#x2F;yum.repos.d&#x2F;nginx.repo</span><br></pre></td></tr></table></figure>
<p>步骤3：写入源文件内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[nginx-stable]</span><br><span class="line">name=nginx stable repo</span><br><span class="line">baseurl=http://nginx.org/packages/centos/$releasever/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">enabled=1</span><br><span class="line">gpgkey=https://nginx.org/keys/nginx_signing.key</span><br><span class="line">module_hotfixes=true</span><br><span class="line"></span><br><span class="line">[nginx-mainline]</span><br><span class="line">name=nginx mainline repo</span><br><span class="line">baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">enabled=0</span><br><span class="line">gpgkey=https://nginx.org/keys/nginx_signing.key</span><br><span class="line">module_hotfixes=true</span><br></pre></td></tr></table></figure>
<p>步骤4：安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install nginx</span><br></pre></td></tr></table></figure>
<p>步骤5： 启动 nginx服务</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">systemctl start nginx</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看状态</span></span><br><span class="line">systemctl status nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> 重启服务</span></span><br><span class="line">systemctl restart nginx</span><br><span class="line"><span class="meta">#</span><span class="bash"> 停止服务</span></span><br><span class="line">systemctl stop nginx</span><br></pre></td></tr></table></figure>
<p>步骤6：临时关闭防火墙 或者把80端口 添加到防火墙</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 临时关闭防火墙</span></span><br><span class="line">systemctl stop firewalld.service</span><br></pre></td></tr></table></figure>
<h5 id="3、测试"><a href="#3、测试" class="headerlink" title="3、测试"></a>3、测试</h5><p>通过本地浏览器访问 虚拟机IP地址 会发现 Nginx</p>
<p><img src="https://exp-picture.cdn.bcebos.com/9881b1fce186242f4342d5ac35e434daf15ee887.jpg?x-bce-process=image/resize,m_lfit,w_500,limit_1/quality,q_80" alt="nginx启动成功"></p>
<p>如果不关闭，默认80端口是不放开的，window主机浏览器 是无法访问到虚拟机上的nginx服务的。</p>
<h5 id="4、其他问题"><a href="#4、其他问题" class="headerlink" title="4、其他问题"></a>4、其他问题</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 永久关闭防火墙命令</span></span><br><span class="line">systemctl disable firewalld</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 关闭selinux</span></span><br><span class="line">vim /etc/selinux/config</span><br><span class="line"></span><br><span class="line">修改</span><br><span class="line">SELINUX=enforcing</span><br><span class="line">为</span><br><span class="line">SELINUX=disabled</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/20/CentOS%E4%B8%AD%E5%AE%89%E8%A3%85nginx/" data-id="cknublgb30000v8uh6tqo1mob" data-title="CentOS中安装nginx" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
</article>



  


  <nav id="page-nav">
    
    <span class="page-number current">1</span><a class="page-number" href="/blog1/page/2/">2</a><a class="page-number" href="/blog1/page/3/">3</a><a class="page-number" href="/blog1/page/4/">4</a><a class="extend next" rel="next" href="/blog1/page/2/">weiter &raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/Flask/" rel="tag">Flask</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/django/" rel="tag">django</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/docker/" rel="tag">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/gitee/" rel="tag">gitee</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/linux/" rel="tag">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/mysql/" rel="tag">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/vue/" rel="tag">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/webshell/" rel="tag">webshell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" rel="tag">云主机实现视频直播</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" rel="tag">关于第三方</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/blog1/tags/CentOS/" style="font-size: 17.5px;">CentOS</a> <a href="/blog1/tags/Flask/" style="font-size: 10px;">Flask</a> <a href="/blog1/tags/django/" style="font-size: 12.5px;">django</a> <a href="/blog1/tags/docker/" style="font-size: 12.5px;">docker</a> <a href="/blog1/tags/gitee/" style="font-size: 10px;">gitee</a> <a href="/blog1/tags/linux/" style="font-size: 10px;">linux</a> <a href="/blog1/tags/mysql/" style="font-size: 12.5px;">mysql</a> <a href="/blog1/tags/python/" style="font-size: 15px;">python</a> <a href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" style="font-size: 17.5px;">python基础知识</a> <a href="/blog1/tags/redis/" style="font-size: 12.5px;">redis</a> <a href="/blog1/tags/vue/" style="font-size: 20px;">vue</a> <a href="/blog1/tags/webshell/" style="font-size: 10px;">webshell</a> <a href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" style="font-size: 10px;">云主机实现视频直播</a> <a href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" style="font-size: 12.5px;">关于第三方</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/03/">三月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/01/">一月 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">docker+CentOS+mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/">mysql实现读写分离</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/">在项目中自动生成接口文档</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/">nginx部署flask项目</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 Jerry<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog1/" class="mobile-nav-link">Home</a>
  
    <a href="/blog1/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/blog1/js/jquery-3.4.1.min.js"></script>



  
<script src="/blog1/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog1/js/script.js"></script>





  </div>
</body>
</html>